home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / goodies / chromakeymovie / windows.c < prev   
Encoding:
Text File  |  2000-09-28  |  5.3 KB  |  212 lines

  1. /*
  2.     File:        windows.c
  3.  
  4.     Contains:    
  5.  
  6.     Written by: Jason Hodges-Harris                
  7.  
  8.     Copyright:    Copyright © 1995-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/28/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24.  
  25. // Mac Toolbox headers
  26.  
  27. #ifndef __DESK__
  28. #include <Desk.h>
  29. #endif
  30.  
  31. #ifndef __DIALOGS__
  32. #include <Dialogs.h>
  33. #endif
  34.  
  35. #ifndef __MEMORY__
  36. #include <Memory.h>
  37. #endif
  38.  
  39. #ifndef __MOVIES__
  40. #include <Movies.h>
  41. #endif
  42.  
  43. #ifndef __TEXTUTILS__
  44. #include <TextUtils.h>
  45. #endif
  46.  
  47. #ifndef __WINDOWS__
  48. #include <Windows.h>
  49. #endif
  50.  
  51.  
  52. // Program headers
  53.  
  54. #ifndef __CHROMAPPHEADER__
  55. #include "ChromaKeyMovie.h"
  56. #endif
  57.  
  58.  
  59. //    Global Variables
  60.  
  61. extern Boolean            gDone;
  62. extern Boolean            gMovieOpen;
  63. extern GWorldPtr        gOffscreenPort,
  64.                         gBackGroundPort,
  65.                         gBackGroundPicture;
  66. extern PixMapHandle        gMoviePixmap,
  67.                         gBackGndPixmap,
  68.                         gBackGndPictPM;
  69.  
  70.  
  71.  /* The DisplayAlert() function is a generic modal dialog display function
  72.     which uses GetStdFilterProc() and SetDialogDefaultItem() to
  73.     automatically get the standard filter and outline the default DITL item.
  74.     These 'undocumented' functions are available in system 7.0 or later. */
  75.  
  76.  #pragma segment Windows
  77. long DisplayAlert (short dialogID,short errStrID,short StrIDindex)
  78. {
  79.     GrafPtr            savePort = nil;
  80.     DialogPtr        myDialog = nil;
  81.     ModalFilterUPP    theFilter = nil;
  82.     Str255            theTextStr;
  83.     short            alertResponse;    
  84.  
  85.     myDialog = GetNewDialog(dialogID,nil,((WindowPtr)-1L));    // get dialog resource
  86.     GetPort(&savePort);
  87.     SetPort    (myDialog);
  88.     if (GetStdFilterProc(&theFilter) !=noErr)
  89.         DebugStr("\pFailed to get standard dialog filter.");
  90.     SetDialogDefaultItem(myDialog,1);
  91.     /* If the errStrID variable contains 0, the dialog doesn't
  92.        require any text from a STR# resource */
  93.     if (errStrID!=0)        // get STR# resource text
  94.     {
  95.         GetIndString(theTextStr,errStrID,StrIDindex);
  96.         ParamText(theTextStr,"\p","\p","\p");
  97.     }
  98.     do{
  99.         ModalDialog(theFilter,&alertResponse);
  100.     } while (alertResponse==0);
  101.     DisposeDialog(myDialog);//    dispose dialog mem allocation
  102.     SetPort(savePort);        
  103.     return alertResponse;    // return dialog return value
  104. }
  105.  
  106.  
  107. // Drag the window from the position passed in the mouseLoc parameter 
  108.  
  109. #pragma segment Windows
  110. void DragSelWind(WindowPtr window,Point mouseLoc)
  111. {
  112.     Rect    dragBounds;
  113.     
  114.     dragBounds=(**GetGrayRgn()).rgnBBox;
  115.     DragWindow(window,mouseLoc,&dragBounds);
  116. }
  117.  
  118.  
  119. // Close the active window which had it's close box selected
  120. #pragma segment Windows
  121. void DoGoAwayWind(WindowPtr window,Point mouseLoc)
  122. {
  123.     if(TrackGoAway(window,mouseLoc))
  124.     {
  125.         if (window!=nil)
  126.         {
  127.             // Test for a dialog window and hide if selected
  128.             if ((((WindowPeek)window)->windowKind)==2) 
  129.                 HideWindow(window);
  130.             // Test for a Desk Accessory window and Close.
  131.             else if ((((WindowPeek)window)->windowKind)<0) 
  132.                 CloseDeskAcc(((WindowPeek)window)->windowKind);
  133.             // Test for an application window.
  134.             else if ((((WindowPeek)window)->windowKind)==8)    
  135.             {
  136.                 DisposeWindowDocs (window);
  137.             }
  138.         }
  139.     }
  140. }
  141.  
  142.  
  143. // Close an application window
  144.  
  145. #pragma segment Windows
  146. void DisposeWindowDocs (WindowPtr window)
  147. {
  148.     MovieDocHndl        myRefcon;
  149.  
  150.     // check if the window to close is a valid Document window
  151.     if ((myRefcon=(MovieDocHndl)GetWRefCon(window)) ==
  152.         (MovieDocHndl)(((WindowPeek)window)->refCon))
  153.     {
  154.         // dispose of the window document structure
  155.         DisposeMovie((**myRefcon).theMovie);
  156.         DisposeHandle((Handle)myRefcon);
  157.         DisposeWindow(window);
  158.  
  159.         // Unlock and Dispose the offscreen GWorlds
  160.         if (gOffscreenPort)
  161.         {
  162.             UnlockPixels(gMoviePixmap);
  163.             UnlockPixels(gBackGndPixmap);
  164.             UnlockPixels(gBackGndPictPM);
  165.             DisposeGWorld(gOffscreenPort);
  166.             DisposeGWorld(gBackGroundPort);
  167.             DisposeGWorld(gBackGroundPicture);
  168.             gBackGroundPicture = gBackGroundPort = gOffscreenPort = nil;
  169.             DoAdjustFileMenu();
  170.         }
  171.     }
  172. }
  173.  
  174.  
  175. // Update "dirty" open window
  176.  
  177. #pragma segment Windows
  178. void    DoWindUpdate(WindowPtr theWindow)
  179. {
  180.     MovieDocHndl        myRefcon = nil;
  181.     PixMapHandle        updatePixMapH = nil;
  182.     WindowPtr            oldPort;
  183.     
  184.     GetPort(&oldPort);                // get old window port
  185.     SetPort(theWindow);                // set to port with update event request
  186.     BeginUpdate(theWindow);            // start update process
  187.      // update the current window's movie
  188.      UpdateMovie((**(MovieDocHndl)GetWRefCon(theWindow)).theMovie);
  189.     EndUpdate(theWindow);            // end update process
  190.     SetPort (oldPort);                // reset active window port
  191. }
  192.  
  193.  
  194. // Open a Movie window, allocate the document structure and place into the window's refCon field.
  195.  
  196. #pragma segment Windows
  197. CWindowPtr    OpenCWindow(void)
  198. {
  199.     CWindowPtr            theWindow;
  200.     MovieDocHndl        theDocHndl;
  201.     Rect                theRect = {0,0,100,100};
  202.     
  203.     theDocHndl = (MovieDocHndl)NewHandle(sizeof(MovieDoc));
  204.     if (theDocHndl == nil)
  205.             DisplayAlert (rGenAlert,rErrMessages,3);
  206.     else
  207.     {
  208.         theWindow = (CWindowPtr)GetNewCWindow(rGenWindow,nil,(WindowPtr)-1L);
  209.         SetWRefCon((WindowPtr)theWindow,(long)theDocHndl);    // set refcon to doc handle
  210.     }
  211.     return theWindow;
  212. }